package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.FristProduct;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IFristProductService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("fristProduct")
public class FristProductController {

    @Autowired
    private IFristProductService fristProductService;

    @RequestMapping("")
    public String index(){
        return "fristProduct";
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(FristProduct product){
        JsonResult jsonResult = new JsonResult();
        try {
            fristProductService.insert(product);
        } catch (Exception e) {
            jsonResult.setMsg("保存失败");
            e.printStackTrace();
        }
        return jsonResult;
    }
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult jsonResult = new JsonResult();
        try {
            fristProductService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            jsonResult.setMsg("删除失败");
            e.printStackTrace();
        }
        return jsonResult;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(FristProduct product){
        JsonResult jsonResult = new JsonResult();
        try {
            fristProductService.updateByPrimaryKey(product);
        } catch (Exception e) {
            jsonResult.setMsg("更新失败");
            e.printStackTrace();
        }
        return jsonResult;
    }
    @RequestMapping("listAll")
    @ResponseBody
    public List<FristProduct> listAll(QueryObject qo){
        return fristProductService.selectAll();
    }
}
